/*
 * Sequence.hpp
 *
 *  Created on: 18 avr. 2012
 *      Author: jd219546
 */

#ifndef SEQUENCE_HPP_
#define SEQUENCE_HPP_

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

struct IdentifiedObject
{
	string my_id;
};
struct Sequence : public IdentifiedObject
{
	string my_sequence;
public:
	Sequence(const char *filename)
	{
		this->read_first_sequence_from_file(filename);
	}
	Sequence(const string  & filename)
	{
		this->read_first_sequence_from_file(filename);
	}
	Sequence(ifstream  & filestream)
	{
		this->read_my_sequence_from_file_stream(filestream);
	}

	int length() const { return my_sequence.length();}
	string::const_iterator begin() const{return my_sequence.begin();}
	string::const_iterator end() const{return my_sequence.end();}
	void read_my_sequence_from_file_stream(ifstream& s){
		string & sequence = this->my_sequence;
		string & name = this->my_id;
		if(s.get()=='>')
			getline(s,name);
		while (!s.eof()){
			int c = s.get(); //get char from reference Sequence file
			if(c == '>'){
				s.unget();
				break;
			}
			else if (c == 'G' || c=='T' || c=='A' || c=='C'){
				sequence.push_back(c);
			}
			// ignore every other chars (newline, etc)
		}
	}

	void read_first_sequence_from_file(const string & filename)
	{
		string & sequence = this->my_sequence;
		string & name = this->my_id;
		ifstream refSeqFile(filename,ios::in);
		ifstream & s = refSeqFile;
		if(s.get()=='>')
			getline(s,name);
		while (!s.eof()){
			int c = s.get(); //get char from reference Sequence file
			if(c == '>'){
				s.unget();
				break;
			}
			else if (c == 'G' || c=='T' || c=='A' || c=='C'){
				sequence.push_back(c);
			}
			// ignore every other chars (newline, etc)
		}
	}

};
#endif /* SEQUENCE_HPP_ */
